package com.lemon.controller;

import com.lemon.entity.Member;
import com.lemon.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/members")
public class MemberController {

    private MemberService MemberService;
    @Autowired
    public MemberController(MemberService memberService){this.MemberService = memberService;}

    @GetMapping
    public List<Member> query() {
        return this.MemberService.queryMemberForList();
    }

    @GetMapping("/{id}")
    public Member selectById(@PathVariable("id") Integer id) {
        return this.MemberService.selectMemberById(id);
    }

    @PostMapping// PUT DELETE都类似
    public Member save(@RequestBody Member member) {
        MemberService.insertMember(member);
        return member;
    }

    @DeleteMapping("/{id}")
    public int delete(@PathVariable("id") Integer id) {
        int rows = this.MemberService.deleteMember(id);
        return rows;
        //return 200;
    }

    @PutMapping
    public Member update(@RequestBody Member member) {
        this.MemberService.updateMember(member);
        return member;
    }

}
